package com.atguigu.lease.web.admin.service.impl;

import com.atguigu.lease.model.entity.SystemPost;
import com.atguigu.lease.model.entity.SystemUser;
import com.atguigu.lease.web.admin.mapper.SystemPostMapper;
import com.atguigu.lease.web.admin.mapper.SystemUserMapper;
import com.atguigu.lease.web.admin.service.SystemUserService;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserItemVo;
import com.atguigu.lease.web.admin.vo.system.user.SystemUserQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author liubo
 * @description 针对表【system_user(员工信息表)】的数据库操作Service实现
 * @createDate 2023-07-24 15:48:00
 */
@Service
public class SystemUserServiceImpl extends ServiceImpl<SystemUserMapper, SystemUser>
        implements SystemUserService {
    @Autowired
    private SystemPostMapper systemPostMapper;
    @Autowired
    private SystemUserMapper systemUserMapper;

    @Override
    public IPage<SystemUserItemVo> pageSystemUserByQuery(IPage<SystemUserItemVo> page, SystemUserQueryVo queryVo) {
//        IPage<SystemUserItemVo> systemUserItemVoIPage = new Page<>();
//        //查询system_user的全部数据,记得带上queryVo
//        QueryWrapper<SystemUser> queryWrapper = new QueryWrapper<>();
//        queryWrapper.like(queryVo.getPhone() != null, "phone", queryVo.getPhone());
//        queryWrapper.like(StringUtils.hasText(queryVo.getName()), "name", queryVo.getName());
//        List<SystemUser> systemUsers = baseMapper.selectList(queryWrapper);
//        //查询system_post表的所有数据，将其转换成Map，其中key为主键id，value为postName
//        List<SystemPost> systemPosts = systemPostMapper.selectList(null);
//        Map<Long, String> collect = systemPosts.stream().collect(Collectors.toMap(SystemPost::getId, SystemPost::getName));
//        List<SystemUserItemVo> records = new ArrayList<>();
//        for (SystemUser systemUser : systemUsers) {
//            SystemUserItemVo systemUserItemVo = new SystemUserItemVo();
//            BeanUtils.copyProperties(systemUser, systemUserItemVo);
//            records.add(systemUserItemVo);
//        }
//        for (SystemUserItemVo systemUserItemVo : records) {
//            systemUserItemVo.setPostName(collect.get(systemUserItemVo.getPostId()));
//        }
//        systemUserItemVoIPage.setRecords(records);
//        systemUserItemVoIPage.setTotal(systemUsers.size());
//        systemUserItemVoIPage.setCurrent(page.getCurrent());
//        systemUserItemVoIPage.setSize(page.getSize());
//        return systemUserItemVoIPage;
        return systemUserMapper.pageSystemUserByQuery(page, queryVo);
    }
}




